package com.baidu.mapapi;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.ArrayList;

public class TransitOverlay extends ItemizedOverlay<OverlayItem>
{
  private ArrayList<a> a;
  private MapView b;
  private Context c;
  private int d;
  private DisplayMetrics e;
  public MKTransitRoutePlan mPlan = null;

  public TransitOverlay(Activity paramActivity, MapView paramMapView)
  {
    super(null);
    this.a = null;
    this.b = null;
    this.c = null;
    this.d = 1;
    this.c = paramActivity;
    this.b = paramMapView;
    this.e = new DisplayMetrics();
    paramActivity.getWindowManager().getDefaultDisplay().getMetrics(this.e);
    if ((this.e.widthPixels <= 320) && (this.e.heightPixels <= 320))
      this.d = 0;
    while (true)
    {
      while (true)
      {
        return;
        if ((this.e.widthPixels > 480) || (this.e.heightPixels > 480))
          break;
        this.d = 1;
      }
      this.d = 2;
    }
  }

  public void animateTo()
  {
    if (size() > 0)
      onTap(0);
  }

  protected OverlayItem createItem(int paramInt)
  {
    Drawable localDrawable;
    char[] arrayOfChar = new char[3];
    arrayOfChar[0] = 108;
    arrayOfChar[1] = 109;
    arrayOfChar[2] = 104;
    String[] arrayOfString = new String[6];
    arrayOfString[0] = "start";
    arrayOfString[1] = "end";
    arrayOfString[2] = "bus";
    arrayOfString[3] = "foot";
    arrayOfString[4] = "rail";
    arrayOfString[5] = "car";
    a locala = (a)this.a.get(paramInt);
    OverlayItem localOverlayItem = new OverlayItem(locala.b, locala.a, null);
    if (locala.c != 3)
    {
      StringBuilder localStringBuilder = new StringBuilder(32);
      localStringBuilder.append("icon_nav_").append(arrayOfString[locala.c]).append('_').append(arrayOfChar[this.d]).append(".png");
      localDrawable = i.a(this.c, localStringBuilder.toString());
      if ((locala.c != 0) && (locala.c != 1))
        break label189;
      localOverlayItem.setMarker(boundCenterBottom(localDrawable));
    }
    while (true)
    {
      return localOverlayItem;
      label189: localOverlayItem.setMarker(boundCenter(localDrawable));
    }
  }

  public boolean draw(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean, long paramLong)
  {
    Projection localProjection = paramMapView.getProjection();
    ((Activity)this.c).getWindowManager().getDefaultDisplay().getMetrics(this.e);
    if (this.mPlan != null)
    {
      int i = this.mPlan.getNumLines();
      int j = this.mPlan.getNumRoute();
      if ((i + 1 == j) && (i != 0))
      {
        Paint localPaint = new Paint();
        localPaint.setAntiAlias(true);
        localPaint.setStrokeWidth(6.0F);
        Point localPoint1 = new Point();
        Point localPoint2 = new Point();
        ArrayList localArrayList1 = new ArrayList();
        int k = paramMapView.getZoomLevel();
        for (int l = 0; l < i; ++l)
        {
          MKRoute localMKRoute1 = this.mPlan.getRoute(l);
          ArrayList localArrayList2 = localMKRoute1.getArrayPoints();
          if ((localArrayList2 != null) && (localArrayList2.size() > 0))
          {
            ArrayList localArrayList6 = (ArrayList)localArrayList2.get(0);
            if ((localArrayList6 != null) && (localArrayList6.size() > 0))
            {
              i.a(localArrayList6, (ArrayList)localMKRoute1.a.get(0), k, localArrayList1);
              int i5 = localArrayList1.size();
              if (i5 > 1)
              {
                localPaint.setColor(Color.rgb(48, 162, 8));
                localPaint.setAlpha(192);
                localProjection.toPixels((GeoPoint)localArrayList1.get(0), localPoint1);
                for (int i6 = 1; i6 < i5; ++i6)
                {
                  localProjection.toPixels((GeoPoint)localArrayList1.get(i6), localPoint2);
                  if (i.a(localPoint1, localPoint2, this.e.widthPixels, this.e.heightPixels))
                    paramCanvas.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y, localPaint);
                  localPoint1.x = localPoint2.x;
                  localPoint1.y = localPoint2.y;
                }
              }
            }
          }
          MKLine localMKLine = this.mPlan.getLine(l);
          ArrayList localArrayList3 = localMKLine.getPoints();
          if ((localArrayList3 != null) && (localArrayList3.size() > 0))
          {
            i.a(localArrayList3, localMKLine.a, k, localArrayList1);
            int i3 = localArrayList1.size();
            if (i3 > 1)
            {
              localPaint.setColor(Color.rgb(58, 107, 189));
              localPaint.setAlpha(192);
              localProjection.toPixels((GeoPoint)localArrayList1.get(0), localPoint1);
              for (int i4 = 1; i4 < i3; ++i4)
              {
                localProjection.toPixels((GeoPoint)localArrayList1.get(i4), localPoint2);
                if (i.a(localPoint1, localPoint2, this.e.widthPixels, this.e.heightPixels))
                  paramCanvas.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y, localPaint);
                localPoint1.x = localPoint2.x;
                localPoint1.y = localPoint2.y;
              }
            }
          }
          if (l == i - 1)
          {
            MKRoute localMKRoute2 = this.mPlan.getRoute(l + 1);
            ArrayList localArrayList4 = localMKRoute2.getArrayPoints();
            if ((localArrayList4 == null) || (localArrayList4.size() <= 0))
              break;
            ArrayList localArrayList5 = (ArrayList)localArrayList4.get(0);
            if ((localArrayList5 == null) || (localArrayList5.size() <= 0))
              break;
            i.a(localArrayList5, (ArrayList)localMKRoute2.a.get(0), k, localArrayList1);
            int i1 = localArrayList1.size();
            if (i1 <= 1)
              break;
            localPaint.setColor(Color.rgb(48, 162, 8));
            localPaint.setAlpha(192);
            localProjection.toPixels((GeoPoint)localArrayList1.get(0), localPoint1);
            int i2 = 1;
            while (true)
            {
              if (i2 >= i1)
                break label844;
              localProjection.toPixels((GeoPoint)localArrayList1.get(i2), localPoint2);
              if (i.a(localPoint1, localPoint2, this.e.widthPixels, this.e.heightPixels))
                paramCanvas.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y, localPaint);
              localPoint1.x = localPoint2.x;
              localPoint1.y = localPoint2.y;
              ++i2;
            }
          }
        }
      }
    }
    label844: return super.draw(paramCanvas, paramMapView, paramBoolean, paramLong);
  }

  protected boolean onTap(int paramInt)
  {
    OverlayItem localOverlayItem = getItem(paramInt);
    this.b.getController().animateTo(localOverlayItem.mPoint);
    if (localOverlayItem.mTitle != null)
      Toast.makeText(this.c, localOverlayItem.mTitle, 1).show();
    super.onTap(paramInt);
    return true;
  }

  public void setData(MKTransitRoutePlan paramMKTransitRoutePlan)
  {
    if (paramMKTransitRoutePlan == null);
    while (true)
    {
      int i;
      int j;
      do
      {
        return;
        this.a = new ArrayList();
        this.mPlan = paramMKTransitRoutePlan;
        i = paramMKTransitRoutePlan.getNumLines();
        j = this.mPlan.getNumRoute();
      }
      while ((i + 1 != j) || (i == 0));
      GeoPoint localGeoPoint1 = paramMKTransitRoutePlan.getStart();
      if (localGeoPoint1 != null)
      {
        a locala1 = new a(this, null);
        locala1.b = localGeoPoint1;
        locala1.c = 0;
        this.a.add(locala1);
      }
      int k = 0;
      if (k < i)
      {
        a locala4;
        MKLine localMKLine = paramMKTransitRoutePlan.getLine(k);
        a locala3 = new a(this, null);
        locala3.b = localMKLine.getGetOnStop().pt;
        locala3.a = localMKLine.a();
        if (localMKLine.getType() == 0)
        {
          locala3.c = 2;
          this.a.add(locala3);
          MKRoute localMKRoute = this.mPlan.getRoute(k + 1);
          locala4 = new a(this, null);
          locala4.b = localMKLine.getGetOffStop().pt;
          locala4.a = localMKRoute.a();
          if (localMKLine.getType() != 0)
            break label251;
          locala4.c = 2;
        }
        while (true)
        {
          while (true)
          {
            while (true)
            {
              this.a.add(locala4);
              ++k;
            }
            locala3.c = 4;
          }
          label251: locala4.c = 4;
        }
      }
      GeoPoint localGeoPoint2 = paramMKTransitRoutePlan.getEnd();
      if (localGeoPoint2 != null)
      {
        a locala2 = new a(this, null);
        locala2.b = localGeoPoint2;
        locala2.c = 1;
        this.a.add(locala2);
      }
      super.populate();
    }
  }

  public int size()
  {
    int i;
    if (this.a == null)
      i = 0;
    while (true)
    {
      return i;
      i = this.a.size();
    }
  }

  private class a
  {
    public String a;
    public GeoPoint b;
    public int c;
  }
}